from django.db import models
from myblog.models import Article


# Create your models here.


class Comment(models.Model):
    name = models.CharField(verbose_name="昵称", max_length=100, )
    email = models.EmailField(verbose_name="邮箱", max_length=255)
    url = models.URLField(verbose_name="网址", blank=True)
    pub_date = models.DateTimeField(verbose_name="发布日期", auto_now_add=True, editable=True)  # 博客发布日期
    text = models.TextField(verbose_name="评论", blank=True, null=True)
    article = models.ForeignKey(Article, on_delete=models.CASCADE, verbose_name='文章')

    def __str__(self):
        """定义每个数据对象的显示信息"""
        return self.name

    class Meta:
        ordering = ['-pub_date']  # 发布日期降序排列
        verbose_name = "评论"  # 在admin站点中显示的名称
        verbose_name_plural = verbose_name  # 显示的复数名称
